package pt.mauromad.guias.utils.transformation;

import pt.mauromad.guias.bean.AccountBean;
import pt.mauromad.guias.bean.AddressBean;
import pt.mauromad.guias.bean.CompanyBean;
import pt.mauromad.guias.bean.ItemBean;
import pt.mauromad.guias.bean.ManifestBean;
import pt.mauromad.guias.bean.ProductBean;
import pt.mauromad.guias.bean.UserBean;
import pt.mauromad.guias.dao.AccountDao;
import pt.mauromad.guias.dao.AddressDao;
import pt.mauromad.guias.dao.CompanyDao;
import pt.mauromad.guias.dao.ProductDao;
import pt.mauromad.guias.dao.UserDao;
import pt.mauromad.guias.dao.manifest.ManifestDao;
import pt.mauromad.guias.dao.manifest.ManifestItemDao;

public class Transformations {
	public static final Transformation<ProductDao, ProductBean> Product2Bean = new Transformation<ProductDao, ProductBean>() {
		@Override
		public ProductBean getSafe(ProductDao obj) {
			ProductBean ret = new ProductBean();

			ret.setId(obj.getId());
			ret.setDescription(obj.getDescription());
			ret.setMeasure(obj.getMeasure());
			ret.setUnitPrice(obj.getUnitPrice());

			return ret;
		};
	};

	public static final Transformation<ProductBean, ProductDao> Product2Dao = new Transformation<ProductBean, ProductDao>() {
		@Override
		public ProductDao getSafe(ProductBean obj) {
			ProductDao ret = new ProductDao();

			ret.setId(obj.getId());
			ret.setDescription(obj.getDescription());
			ret.setMeasure(obj.getMeasure());
			ret.setUnitPrice(obj.getUnitPrice());

			return ret;
		};
	};

	public static final Transformation<ManifestItemDao, ItemBean> Item2Bean = new Transformation<ManifestItemDao, ItemBean>() {
		@Override
		public ItemBean getSafe(ManifestItemDao dao) {
			ItemBean bean = new ItemBean();

			// if (dao.getManifest() != null)
			// bean.setManifestId(dao.getManifest().getId());

			bean.setId(dao.getId());
			// bean.setDescription(dao.getDescription());
			// bean.setUnit(dao.getUnit());
			// bean.setUnitPrice(dao.getUnitPrice());
			// bean.setQuantity(dao.getQuantity());
			// bean.setDocReference(dao.getDocReference());

			return bean;
		};
	};

	public static final Transformation<ItemBean, ManifestItemDao> Item2Dao = new Transformation<ItemBean, ManifestItemDao>() {
		@Override
		public ManifestItemDao getSafe(ItemBean bean) {
			ManifestItemDao dao = new ManifestItemDao();

			// if (bean.getManifestId() != null) {
			// ManifestDao temp = new ManifestDao();
			// temp.setId(bean.getManifestId());
			// dao.setManifest(temp);
			// }
			//
			// dao.setId(bean.getId());
			// // dao.setDescription(bean.getDescription());
			// // dao.setUnit(bean.getUnit());
			// // dao.setUnitPrice(bean.getUnitPrice());
			// dao.setQuantity(bean.getQuantity());
			// dao.setDocReference(bean.getDocReference());

			return dao;
		}
	};

	public static final Transformation<ManifestDao, ManifestBean> Manifest2Bean = new Transformation<ManifestDao, ManifestBean>() {
		@Override
		public ManifestBean getSafe(ManifestDao dao) {
			ManifestBean bean = new ManifestBean();

			bean.setId(dao.getId());
			bean.setOriginAddress(dao.getOriginAddress());
			bean.setDestinationAddress(dao.getDestinationAddress());
			bean.setShippingAddress(dao.getShippingAddress());
			bean.setDeliveryAddress(dao.getDeliveryAddress());
			bean.setDocumentType(dao.getDocumentType());
			bean.setStartDate(dao.getStartDate());
			bean.setEndDate(dao.getEndDate());
			bean.setVehicleId(dao.getVehicleId());
			// bean.setItems((List<ItemBean>) Item2Bean.get(dao.getItems()));

			return bean;
		}
	};

	public static final Transformation<ManifestBean, ManifestDao> Manifest2Dao = new Transformation<ManifestBean, ManifestDao>() {
		@Override
		public ManifestDao getSafe(ManifestBean obj) {
			ManifestDao ret = new ManifestDao();

			ret.setId(obj.getId());
			ret.setOriginAddress(obj.getOriginAddress());
			ret.setDestinationAddress(obj.getDestinationAddress());
			ret.setShippingAddress(obj.getShippingAddress());
			ret.setDeliveryAddress(obj.getDeliveryAddress());
			ret.setDocumentType(obj.getDocumentType());
			ret.setStartDate(obj.getStartDate());
			ret.setEndDate(obj.getEndDate());
			ret.setVehicleId(obj.getVehicleId());
			// ret.setItems((List<ItemDao>) Item2Dao.get(obj.getItems()));

			return ret;
		}
	};

	public static final Transformation<AddressDao, AddressBean> Address2Bean = new Transformation<AddressDao, AddressBean>() {
		@Override
		public AddressBean getSafe(AddressDao obj) {
			AddressBean ret = new AddressBean();

			ret.setId(obj.getId());
			ret.setAddress(obj.getAddress());
			ret.setCity(obj.getCity());
			ret.setPostalCode(obj.getPostalCode());
			ret.setDescription(obj.getDescription());

			return ret;
		}
	};

	public static final Transformation<AddressBean, AddressDao> Address2Dao = new Transformation<AddressBean, AddressDao>() {
		@Override
		public AddressDao getSafe(AddressBean obj) {
			AddressDao ret = new AddressDao();

			ret.setId(obj.getId());
			ret.setAddress(obj.getAddress());
			ret.setCity(obj.getCity());
			ret.setPostalCode(obj.getPostalCode());
			ret.setDescription(obj.getDescription());

			return ret;
		}
	};

	public static final Transformation<CompanyDao, CompanyBean> Company2Bean = new Transformation<CompanyDao, CompanyBean>() {
		@Override
		public CompanyBean getSafe(CompanyDao obj) {
			CompanyBean ret = new CompanyBean();

			ret.setId(obj.getId());
			ret.setName(obj.getName());
			ret.setFiscalNumber(obj.getFiscalNumber());
			ret.setEnabled(obj.isEnabled());
			ret.setAddresses(obj.getAddresses());

			return ret;
		}
	};

	public static final Transformation<CompanyBean, CompanyDao> Company2Dao = new Transformation<CompanyBean, CompanyDao>() {
		@Override
		public CompanyDao getSafe(CompanyBean obj) {
			CompanyDao ret = new CompanyDao();

			ret.setId(obj.getId());
			ret.setName(obj.getName());
			ret.setFiscalNumber(obj.getFiscalNumber());
			ret.setEnabled(obj.getEnabled());
			ret.setMainAddress(obj.getMainAddress());

			return ret;
		}
	};

	public static final Transformation<UserDao, UserBean> User2Bean = new Transformation<UserDao, UserBean>() {
		@Override
		public UserBean getSafe(UserDao dao) {
			UserBean bean = new UserBean();

			bean.setId(dao.getId());
			bean.setUsername(dao.getUsername());
			bean.setPassword(dao.getPassword());
			bean.setFirstName(dao.getFirstName());
			bean.setLastName(dao.getLastName());

			return bean;
		}
	};

	public static final Transformation<UserBean, UserDao> User2Dao = new Transformation<UserBean, UserDao>() {
		@Override
		public UserDao getSafe(UserBean bean) {
			UserDao dao = new UserDao();

			dao.setId(bean.getId());
			dao.setUsername(bean.getUsername());
			dao.setPassword(bean.getPassword());
			dao.setFirstName(bean.getFirstName());
			dao.setLastName(bean.getLastName());

			return dao;
		}
	};

	public static final Transformation<AccountDao, AccountBean> Account2Bean = new Transformation<AccountDao, AccountBean>() {
		@Override
		public AccountBean getSafe(AccountDao obj) {
			AccountBean ret = new AccountBean();

			ret.setId(obj.getId());
			ret.setDomain(obj.getDomain());
			ret.setEnabled(obj.isEnabled());
			ret.setCompanies(obj.getCompanies());
			ret.setUsers(obj.getUsers());

			return ret;
		}
	};

	public static final Transformation<AccountBean, AccountDao> Account2Dao = new Transformation<AccountBean, AccountDao>() {
		@Override
		public AccountDao getSafe(AccountBean obj) {
			AccountDao ret = new AccountDao();

			ret.setId(obj.getId());
			ret.setDomain(obj.getDomain());
			ret.setEnabled(obj.isEnabled());
			ret.setDomain(obj.getDomain());

			return ret;
		}
	};
}
